package com.bss.model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "attendent")
public class Attendent extends Person {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8842931510471947798L;

	@NotNull(message = "{attendent.name.NotNull}")
	@Size(min = 1, max = 45, message = "{attendent.name.Size}")
	private String name;

	private Relationship relationship;

	private Patient patient;

	private Set<CurrentAttendent> currentAttendents;

	public void setCurrentAttendents(
			final Set<CurrentAttendent> currentAttendents) {
		this.currentAttendents = currentAttendents;
	}

	@NotNull(message = "{attendent.relationship.NotNull}")
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idRelationship")
	public Relationship getRelationship() {
		return this.relationship;
	}

	public void setRelationship(final Relationship relationship) {
		this.relationship = relationship;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idPatient")
	public Patient getPatient() {
		return this.patient;
	}

	public void setPatient(final Patient patient) {
		this.patient = patient;
	}

	public void setName(final String name) {
		this.name = name;
	}

	@Column(name = "name", /* nullable = false, */length = 45)
	public String getName() {
		return this.name;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "attendent")
	public Set<CurrentAttendent> getCurrentAttendents() {
		return this.currentAttendents;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Attendent other = (Attendent) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.toLowerCase().equalsIgnoreCase(
				other.name.toLowerCase()))
			return false;
		if (patient == null) {
			if (other.patient != null)
				return false;
		} else if (patient.getId().intValue() != other.patient.getId()
				.intValue())
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Attendent [name=" + name + ", relationship=" + relationship
				+ ", patientId=" + patient.getId() + "]";
	}

}
